﻿@model CNFM_CROCODILE_LOGO.Core.Domain.ViewModels.EnterpriseModels

@{
    ViewData["Title"] = "企业Edit";
}

<style>
    .layui-form-select dl dd {
        z-index: 999
    }
</style>
@section Scripts
    {
    <script type="text/javascript">
        var selfLayer = null, page = 1, active = null;
        layui.use(['form', 'layedit', 'treeSelect', 'table', 'laydate', 'upload'], function () {
            var form = layui.form, table = layui.table, upload = layui.upload, treeSelect = layui.treeSelect; //表格

            layui.laydate.render({ elem: '#RegisteredTime' });
            layui.laydate.render({ elem: '#XYStartDate' });
            layui.laydate.render({ elem: '#XYEndDate' });
            layui.laydate.render({ elem: '#JYStartDate' });
            layui.laydate.render({ elem: '#JYEndDate' });

            var imageUrlxy;
            var imageUrljy;

            //地区
            treeSelect.render({
                // 选择器
                elem: '#UnCode',
                // 数据
                data: '/User/GetAreaTreeAll?code=' + localStorage.getItem("X-AreCode"),
                // 请求头
                //  headers: { 'Authorization': 'Bearer ' + localStorage.getItem("X-TOKEN") },

                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '地区',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function (d) {
                    // console.log(d);
                },
                // 加载完成后的回调函数
                success: function (d) {

                    //  console.log(d);

                    //                选中节点，根据id筛选
                    treeSelect.checkNode('pidSelect', $("#UnCode").val());

                    // console.log($('#varProjectName').val());

                    //                获取zTree对象，可以调用zTree方法
                    var treeObj = treeSelect.zTree('UnCode');
                    console.log(treeObj);

                    //                刷新树结构
                    treeSelect.refresh('pidSelect');
                }
            });
            //省市区联动
            axios.get('/Area/GetAreaSelectAll', {
                params: {
                    //type: data.value
                }
            }).then(function (result) {
                if (result.data.code == 200) {
                    var options = '<option value="">请选择省份</option>';
                    var resultdata = result.data.result.data;
                    if (resultdata != null) {
                        console.log("258");
                        console.log(resultdata);
                        for (var i = 0; i < resultdata.length; i++) {
                            options += '<option value="' + resultdata[i].name + '">' + resultdata[i].name + '</option>';
                        }
                    }

                    if ($("#province"))
                        $("#province").html(options);
                    form.render();
                } else {
                    alert(result.data.msg)
                }
            }).catch(function (error) {
                console.log(error);
            });

            var JYUrl = "@ViewData["JYUrl"]";
            var XYUrl = "@ViewData["XYUrl"]";
            $("#jyImageZS").attr("src", JYUrl)
            $("#xyImageZS").attr("src", XYUrl)

            //图片上传(xyImage)
            var uploadInst = upload.render({
                elem: '#xyImage'
                // , auto: false
                , acceptMime: 'image/*'
                // ,method: 'post' //上传接口的http类型   //   https://localhost:5001/api/Upload/UploadFile
                , url: 'https://localhost:5001/api/Upload/UploadFile?typeName=企业驯养许可证&id=' + $('#Id').val()
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    //obj.preview(function (index, file, result) {
                    //    $('#demo1').attr('src', result); //图片链接（base64）
                    //});
                }
                , done: function (res) {
                    //如果上传失败
                    if (res == null) {

                        return layer.msg('上传失败');
                    }
                    else {
                        console.log("123456");
                        console.log(res);

                        imageUrlxy = res[0];
                        $("#xyImageZS").attr("src", res.data)
                        return layer.msg('上传成功');

                    }
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

            //图片上传(jyImage)
            var uploadInst = upload.render({
                elem: '#jyImage'
                // , auto: false
                , acceptMime: 'image/*'
                // ,method: 'post' //上传接口的http类型   //   https://localhost:5001/api/Upload/UploadFile
                , url: 'https://localhost:5001/api/Upload/UploadFile?typeName=企业经营许可证&id=' + $('#Id').val()
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    //obj.preview(function (index, file, result) {
                    //    $('#demo1').attr('src', result); //图片链接（base64）
                    //});
                }
                , done: function (res) {
                    //如果上传失败
                    if (res == null) {

                        return layer.msg('上传失败');
                    }
                    else {
                        console.log("123456");
                        console.log(res);

                        imageUrljy = res[0];
                        $("#jyImageZS").attr("src", res.data)
                        return layer.msg('上传成功');

                    }
                    //上传成功
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });

            //监听提交
            form.on('submit(submit)', function (data) {
                // data.field
                console.log(JSON.stringify(table.cache.dataList));
                // data.field.Enterprises = JSON.stringify(table.cache.dataList);
                //   console.log(data.field);
                data.field.Enterprisestring = JSON.stringify(table.cache.dataList);
                //  console.log(JSON.stringify(table.cache));
                axios({
                    method: 'post',
                    url: '/Enterprise/AddUpdateEnterprise',
                    //headers: {
                    //    'content-type': 'application/x-www-form-urlencoded'
                    //},
                    data: data.field
                })
                    .then(function (response) {
                        console.log(response);
                        if (response.data.code == 200) {
                            javascript: history.go(-1);
                        } else {
                            alert(response.data.msg)
                        }

                    }).catch(function (error) {
                        console.log("添加失败!" + error);
                    });
                return false;
            });

        });
    </script>
}

<form class="layui-form layui-form-pane" asp-action="Edit">
    <div class="layui-form-item">
        <label class="layui-form-label">企业名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="EnterpriseName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="RegisteredTime">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地区编码</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" lay-filter="pidSelect" asp-for="UnCode">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="Address">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">养殖地点</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="Address">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业法人</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="LegalPerson">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="Person">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" lay-verify="required" asp-for="Telephone">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮编</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="ZipCode">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="Email">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">驯养繁殖许可证</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="XYLicense">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">驯养繁殖许可证(图)</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="xyImage">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <img id="xyImageZS" class="layui-upload-img" style="max-height:38px; max-width:50px;" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">有效日期</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="XYStartDate">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="XYEndDate">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">经营许可证</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="JYLicense">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">经营许可证(图)</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="jyImage">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <img id="jyImageZS" class="layui-upload-img" style="max-height:38px; max-width:50px;" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">有效日期</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="JYStartDate">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="JYEndDate">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">核定数量</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="ApprovedSum">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">核定单位(人)</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="ApprovedName">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">行政部门核实</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input w_545" autocomplete="off" asp-for="ApprovedDepartment">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea asp-for="Details" style="width:545px;height:100px"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea asp-for="Remarks" style="width:545px;height:100px"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn" type="button" style="width: 100px" lay-submit lay-filter="submit" value="立即提交" />
            <button type="reset" style="width: 100px" class="layui-btn layui-btn-primary">重置</button>
            <a style="width: 100px" class="layui-btn layui-btn-primary" asp-action="List">返回</a>
        </div>
    </div>
    <input type="hidden" asp-for="Id" />
</form>

